from prettytable import PrettyTable

from battle import Battle
from commom import clearConsole


class Game:

    def __init__(self, nickname):
        self.nickname = nickname
        self.total = 0
        self.win = 0
        self.defeat = 0
        self.level = 0
        self.game_record = []

    def run(self):
        while True:
            clearConsole()
            tb = PrettyTable(['欢迎来到是男人就上10层'])
            tb.add_row([f'英雄昵称:{self.nickname}'])
            tb.add_row([f'总局数:{self.total}'])
            tb.add_row([f'通关次数:{self.win}'])
            tb.add_row([f'失败统计:{self.defeat}'])
            tb.add_row([f'最高层数:{self.level}'])
            print(tb)
            order = input('输入s【开始游戏】/q【退出游戏】:')
            if order == 'q':
                print('下次再见！')
                exit(0)
            elif order == 's':
                if self.game_start():
                    self.win += 1
                else:
                    self.defeat += 1
                self.total += 1
            else:
                input('输入错误，请重新输入/按回车继续...')

    def game_start(self):
        battle = Battle(self.nickname)
        is_win, last_level = battle.start()
        if last_level > self.level:
            self.level = last_level
        return is_win

    def list_record(self):
        pass
